package com.qubuyer.business.home.model

import com.qubuyer.core.ext.toJson
import com.qubuyer.core.framework.BaseModel
import com.qubuyer.core.http.HttpResult
import com.qubuyer.repository.entitys.*
import com.qubuyer.repository.services.ApiService
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody


class HomeModel : BaseModel() {

    private val api: ApiService by injectApi()

    suspend fun loadBanner(): HttpResult<List<HomeBannerEntity>?> {
        return api.banner()
    }

    suspend fun loadCate(): HttpResult<List<HomeCategoryEntity>?> {
        return api.cate()
    }

    suspend fun loadSaleTop(): HttpResult<HomeSaleTopEntity?> {
        return api.distribute()
    }

    suspend fun loadGoodInfo(type: String? = null): HttpResult<List<HomeGoodEntity>?> {
        return api.homeRecommend(type)
    }

    suspend fun loadLimitGoodInfo(): HttpResult<List<HomeGoodEntity>?> {
        return api.buyLimit()
    }

    suspend fun loadSuperReturnGoodInfo(): HttpResult<List<HomeGoodEntity>?> {
        return api.returnGoods()
    }

    suspend fun loadDailyDiscountGoodInfo(): HttpResult<List<HomeGoodEntity>?> {
        return api.discount()
    }

    suspend fun unSendNumber(): HttpResult<UserMessageCountEntity?> {
        return api.unSendNumber()
    }

    suspend fun hotRecommend(page: Int): HttpResult<List<HomeGoodEntity>?> {
        return api.hotRecommend(mapOf(Pair("page", page.toString()), Pair("limit", "10")).toJson().toRequestBody("application/json; charset=utf-8".toMediaType()))
    }
}